package com.app.h5.util;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.WindowManager;


/**
 * 获取屏幕尺寸工具类
 * Created by Dave on 2016/12/15.
 */

public class ScreenUtil {
    public static final String TAG = "ScreenUtil";

    private static DisplayMetrics getDisplayMetrics(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics;
    }

    public static int getScreenWid(Context context) {
        return getDisplayMetrics(context).widthPixels;
    }

    public static int getScreenHei(Context context) {
        return getDisplayMetrics(context).heightPixels;
    }

    /**
     * 获取状态栏高度
     */
    public static int getStatusBarSize(Context context) {
        int statusBarHeight = -1;
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = resources.getDimensionPixelSize(resourceId);
        }
        //DebugUtil.logD(TAG, "statusBarHeight=" + statusBarHeight);
        return statusBarHeight;
    }

    /**
     * 获取导航栏高度
     *
     * @param context
     * @return
     */
    public static int getNavHeight(Context context) {
        int rid = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
        if (rid != 0) {
            int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
            return context.getResources().getDimensionPixelSize(resourceId);
        } else
            return 0;
    }

}
